# -*- coding:utf-8 -*-
#作者：琴弦上的宇宙
#时间：2021年10月22日

from tkinter import *
from tkinter import ttk,filedialog
import tkinter.messagebox
import time
import configparser

#时钟
class Watch(Frame):
    msec=1000
    def __init__(self,parent=None,**kw):
        Frame.__init__(self,parent,kw)
        self._running=False
        self.timeStr=StringVar()
        self._start=time.time()
        self.makeWidgets()
    def makeWidgets(self):
        l1=Label(self,textvariable=self.timeStr,font=("",12))
        l1.pack()
    def _update(self):
        self._settime()
        self.timer=self.after(self.msec,self._update)
    def _settime(self):
        hours='{:0>2d}'.format(int((time.time()-self._start)/3600))
        minutes='{:0>2d}'.format(int((time.time()-self._start)/60%60))
        today=str(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())))+\
            ' 已启动'+hours+':'+minutes+' 重启'+str(MyGui.gRebootCnt)+'次'
        self.timeStr.set(today)
    def start(self):
        self._update()
        self.place(x=85,y=370)

#状态
class Status(Frame):
    msec=1000
    def __init__(self,parent=None,**kw):
        Frame.__init__(self,parent,kw)
        self._running=False
        self.status1Str=StringVar()
        self.status2Str=StringVar()
        self.status3Str=StringVar()
        self.status4Str=StringVar()
        self.makeWidgets()
    def makeWidgets(self):
        l1=Label(self,textvariable=self.status1Str,font=("",12),foreground='blue')
        l1.pack()
        l2=Label(self,textvariable=self.status2Str,font=("",12),foreground='blue')
        l2.pack()
        l3=Label(self,textvariable=self.status3Str,font=("",12),foreground='blue')
        l3.pack()
        l4=Label(self,textvariable=self.status4Str,font=("",12),foreground='green')
        l4.pack()
    def _update(self):
        self._setStatus()
        self.timer=self.after(self.msec,self._update)
    def _setStatus(self):
        abandon='全力通关中'
        if MyGui.bTaskRunning:
            abandon='正在做任务中'
        elif MyGui.gAbandon==88:
            abandon='寻找神秘人中'
        elif MyGui.gAbandon==999:
            abandon='正在挂机中'
        elif MyGui.gAbandon<=3 and MyGui.gAbandon>=1:
            abandon=str(MyGui.gAbandon)+'关后放弃拿碎片'
        MyGui.gLoopAllCnt=MyGui.gFinish+MyGui.gQuitCnt
        status1=\
            '总计='+str(MyGui.gLoopAllCnt)+\
            ' 通关='+str(MyGui.gFinish)+\
            ' 弃/败='+str(MyGui.gQuitCnt)+\
            ' 完成任务='+str(MyGui.gTaskFinishCnt)
        self.status1Str.set(status1)
        tmp='0'
        if MyGui.gSurpriseAllCnt>0:
            tmp=str(int((MyGui.gSurpriseTaskCnt+MyGui.gSurpriseOverCnt) \
                *100/MyGui.gSurpriseAllCnt))
        status2=\
            '惊喜='+str(MyGui.gSurpriseAllCnt)+\
            ' 错过惊喜='+str(MyGui.gSurpriseMissCnt)+\
            ' 神秘人概率='+tmp+'%'
        self.status2Str.set(status2)
        status3=\
            ' 神秘人='+str(MyGui.gSurpriseTaskCnt+MyGui.gSurpriseOverCnt)+\
            ' 新任务='+str(MyGui.gSurpriseTaskCnt)+\
            ' 溢出任务='+str(MyGui.gSurpriseOverCnt)
        self.status3Str.set(status3)
        status4=\
            '小关='+str(MyGui.gRound)+'/'+abandon+\
            ' 战斗='+str(MyGui.gContinue)+'/'+str(MyGui.gInterval)+'秒'
        self.status4Str.set(status4)
    def start(self):
        self._update()
        self.place(x=110,y=250)

#调试
class Debug(Frame):
    msec=100
    def __init__(self,parent=None,**kw):
        Frame.__init__(self,parent,kw)
        self._running=False
        self.logStr=StringVar()
        self.makeWidgets()
    def makeWidgets(self):
        l1=Label(self,textvariable=self.logStr,foreground='red',font=("",11))
        l1.pack()
    def _update(self):
        self._setLog()
        self.timer=self.after(self.msec,self._update)
    def _setLog(self):
        log=str(MyGui.gLog)
        log=log.replace('resource/','')
        log=log.replace('.png','')
        self.logStr.set(log)
    def start(self):
        self._update()
        self.place(x=10,y=340)

#调试
class Wait(Frame):
    msec=100
    def __init__(self,parent=None,**kw):
        Frame.__init__(self,parent,kw)
        self._running=False
        self.waitStr=StringVar()
        self.makeWidgets()
    def makeWidgets(self):
        l1=Label(self,textvariable=self.waitStr,foreground='red',font=("",11))
        l1.pack()
    def _update(self):
        self._setWait()
        self.timer=self.after(self.msec,self._update)
    def _setWait(self):
        if MyGui.gWait>=0.1:
            MyGui.gWait-=0.1
        if MyGui.gAbandon==999 and MyGui.gHookTime>=0.1:
            MyGui.gHookTime-=0.1
            MyGui.gRunTime=time.time()
        wait=str(round(MyGui.gWait,1))
        self.waitStr.set(wait+'s RM')
    def start(self):
        self._update()
        self.place(x=10,y=370)

class MyGui(object):

    bSaveErrorPng=False
    gLog=None

    bSaveAwardPng=False
    gSurpriseAllCnt=0
    gSurpriseTaskCnt=0
    gSurpriseOverCnt=0
    gSurpriseMissCnt=0

    bSaveTaskPng=True
    gTaskFinishCnt=0

    gLoopAllCnt=0
    gFinish=0
    gQuitCnt=0
    gRound=0

    bResetScene=False
    gContinue=0
    gHookTime=0

    gRebootCnt=0
    gWait=0.0

    bAutoAi=False
    bRunning=False
    gRunTime=time.time()

    bTaskRunning=False
    bTaskLevel=False
    gTaskDifficulty='2'
    gTaskLevel='1-1'
    gTaskAbandon=99

    #界面配置
    gBattlePath=None
    gGameMode='1'
    gDifficulty='1'
    gLevel='2-5'
    gAbandon=99
    gViewTask=0
    gSkill='1'
    gCard='1-1'
    gInterval=600
    gStartTime=None
    gEndTime=None

    G_TASK_TIME=(60*60)
    G_HOOK_TIME=(18*60)
    G_MAIN_TITLE='炉石AI--By琴弦上的宇宙--2021-12-08'

    G_LIST_MODE=['PVE卤蛋对对碰']
    G_LIST_ZONE=['普通','英雄']
    G_LIST_FIGHT=['全力通关','神秘人后放弃','挂机升级战令(20分钟)','1小关后放弃','2小关后放弃','3小关后放弃']
    G_LIST_SKILL=['AOE后优先1(火焰队)','AOE后优先2技能','AOE后优先3技能',\
                 'AOE后随机1/2/3技能','必优先1技能(自然队)','必优先2技能',\
                 '必优先3技能','1/2/3技能随机']
    G_LIST_CARD=['第1行第1个','第1行第2个','第1行第3个',\
                 '第2行第1个','第2行第2个','第2行第3个',\
                 '第3行第1个','第3行第2个','第3行第3个']
    G_TIP_INFO='''
环境配置:
1.Python环境安装完成后，直接双击运行stoneMain.py即可
2.战网启动器必须选择战网目录下“Battle.net Launcher.exe”
（不能选择“Battle.net.exe”）
3.系统显示->缩放与布局：必须使用100%大小
（不能放大125%或缩小80%等，否则无法重新启动炉石）
4.炉石分辨率必须改为1024x768（推荐）或1366x768，其他分辨率不支持
（炉石设置没有对应分辨率选项时，可以手动调整炉石窗口大小）
5.封装版即stoneMain.exe不支持在Windows7上使用
（请升级系统至Windows10或使用Python版本）

功能设置:
1.所有功能设置后，都必须点击保存，最好重新打开软件运行
2.自动做任务时，选择普通2-6和神秘人放弃，然后选择1/2/3技能随机
3.点击运行按钮后会最小化，禁止操作鼠标，否则会出错，需要重新打开软件
'''

    G_BATTLE_TITLE='战网启动器：'
    G_MODE_TITLE='游戏模式：'
    G_ZONE_TITLE='副本选择：'
    G_SKILL_TITLE='技能选择：'
    G_CARD_TITLE='卡组选择：'
    G_LOOP_TITLE='防掉线检测：'
    G_MONITOR_TITLE='监控时间段：'
    G_STATUS_TITLE='运行状态：'
    G_AUTO_TASK='自动做任务'
    G_BATTLE_BTN='选择启动器'
    G_TIP_BTN='使用说明书'
    G_SAVE_BTN='保存'

    def __init__(self):

        #读取配置文件
        config=configparser.ConfigParser()
        config.read("config/config.ini",encoding="utf8")
        MyGui.gBattlePath=config.get('config','battlepath').replace('\n','')
        MyGui.gGameMode=config.get('config','gamemode').replace('\n','')
        MyGui.gDifficulty=config.get('config','difficulty').replace('\n','')
        MyGui.gLevel=config.get('config','level').replace('\n','')
        MyGui.gAbandon=int(config.get('config','abandon').replace('\n',''))
        MyGui.gViewTask=int(config.get('config','task').replace('\n',''))
        MyGui.gSkill=config.get('config','skill').replace('\n','')
        MyGui.gCard=config.get('config','card').replace('\n','')
        MyGui.gInterval=int(config.get('config','interval').replace('\n',''))
        MyGui.gStartTime=config.get('config','starttime').replace('\n','')
        MyGui.gEndTime=config.get('config','endtime').replace('\n','')

        self.win=Tk()
        self.win.title(MyGui.G_MAIN_TITLE) #标题
        self.win.attributes('-alpha',1.0) #透明度
        self.win.attributes('-topmost',True) #置顶
        self.win.geometry("420x400+0+340") #大小和位置
        self.win.resizable(width=False,height=False)
        self.picStart=PhotoImage(file='resource/start.png')
        self.picStop=PhotoImage(file='resource/stop.png')

        self.lbBattle=Label(self.win,text=MyGui.G_BATTLE_TITLE,font=("",12))
        self.lbBattle.place(x=10,y=10)
        self.textBattle=Text(self.win,width=22,height=1,font=("",12),foreground='grey')
        self.textBattle.place(x=120,y=10)
        self.textBattle.delete(0.0,END)
        self.textBattle.insert(INSERT,MyGui.gBattlePath)
        self.textBattle.config(state=DISABLED)
        self.btnBattle=Button(self.win,text=MyGui.G_BATTLE_BTN,font=("",12),command=self.setBattle)
        self.btnBattle.place(x=315,y=10)

        self.btnTip=Button(self.win,text=MyGui.G_TIP_BTN,font=("",12),
            foreground='red',command=self.tipInfo)
        self.btnTip.place(x=315,y=50)

        self.lbGameMode=Label(self.win,text=MyGui.G_MODE_TITLE,font=("",12))
        self.lbGameMode.place(x=10,y=40)
        self.cmbGameMode=ttk.Combobox(self.win,width=13,font=("",12))
        self.cmbGameMode['values']=MyGui.G_LIST_MODE
        self.cmbGameMode['state']='readonly'
        game=MyGui.gGameMode.replace('\n','')
        self.cmbGameMode.current(int(game)-1)
        self.cmbGameMode.place(x=120,y=40)
        self.btnGameMode=Button(self.win,text=MyGui.G_SAVE_BTN,width=5,height=1,\
            font=("",12),command=self.setGameMode)
        self.btnGameMode.place(x=250,y=37)

        self.lbZone=Label(self.win,text=MyGui.G_ZONE_TITLE,font=("",12))
        self.lbZone.place(x=10,y=70)
        self.cmbZone=ttk.Combobox(self.win,width=5,font=("",12))
        self.cmbZone['values']=MyGui.G_LIST_ZONE
        self.cmbZone['state']='readonly'
        diffcult=MyGui.gDifficulty.replace('\n','')
        self.cmbZone.current(int(diffcult)-1)
        self.cmbZone.place(x=120,y=70)
        self.textZone=Text(self.win,width=5,height=1,font=("",12))
        self.textZone.place(x=195,y=70)
        self.textZone.delete(0.0,END)
        self.textZone.insert(INSERT,MyGui.gLevel)
        self.cmbFight=ttk.Combobox(self.win,width=12,font=("",12))
        self.cmbFight['values']=MyGui.G_LIST_FIGHT
        self.cmbFight['state']='readonly'
        if MyGui.gAbandon==99:
            self.cmbFight.current(0)
        elif MyGui.gAbandon==88:
            self.cmbFight.current(1)
        elif MyGui.gAbandon==999:
            self.cmbFight.current(2)
        elif MyGui.gAbandon<=3 and MyGui.gAbandon>=1:
            self.cmbFight.current(MyGui.gAbandon+2)
        self.cmbFight.place(x=120,y=100)
        self.checkVar=StringVar(value='0')
        self.check=Checkbutton(self.win,text=MyGui.G_AUTO_TASK,\
            variable=self.checkVar,width=12,font=("",10))
        if MyGui.gViewTask==1:
            self.check.select()
        self.check.place(x=5,y=100)
        self.btnZone=Button(self.win,text=MyGui.G_SAVE_BTN,width=5,height=2,\
            font=("",12),command=self.setZone)
        self.btnZone.place(x=250,y=73)

        self.lbSkill=Label(self.win,text=MyGui.G_SKILL_TITLE,font=("",12))
        self.lbSkill.place(x=10,y=130)
        self.cmbSkill=ttk.Combobox(self.win,width=13,font=("",12))
        self.cmbSkill['values']=MyGui.G_LIST_SKILL
        self.cmbSkill['state']='readonly'
        skill=MyGui.gSkill.replace('\n','')
        self.cmbSkill.current(int(skill)-1)
        self.cmbSkill.place(x=120,y=130)
        self.btnSkill=Button(self.win,text=MyGui.G_SAVE_BTN,width=5,height=1,\
            font=("",12),command=self.setSkill)
        self.btnSkill.place(x=250,y=127)

        self.lbCard=Label(self.win,text=MyGui.G_CARD_TITLE,font=("",12))
        self.lbCard.place(x=10,y=160)
        self.cmbCard=ttk.Combobox(self.win,width=13,font=("",12))
        self.cmbCard['values']=MyGui.G_LIST_CARD
        self.cmbCard['state']='readonly'
        card1=MyGui.gCard.replace('\n','').split('-')
        self.cmbCard.current(3*(int(card1[0])-1)+(int(card1[1])-1))
        self.cmbCard.place(x=120,y=160)
        self.btnCard=Button(self.win,text=MyGui.G_SAVE_BTN,width=5,height=1,\
            font=("",12),command=self.setCard)
        self.btnCard.place(x=250,y=157)

        self.lbInterval=Label(self.win,text=MyGui.G_LOOP_TITLE,font=("",12))
        self.lbInterval.place(x=10,y=190)
        self.lbInterval2=Label(self.win,text='秒',font=("",12))
        self.lbInterval2.place(x=200,y=190)
        self.textInterval=Text(self.win,width=8,height=1,font=("",12))
        self.textInterval.place(x=120,y=190)
        self.textInterval.delete(0.0,END)
        self.textInterval.insert(INSERT,MyGui.gInterval)
        self.btnInterval=Button(self.win,text=MyGui.G_SAVE_BTN,width=5,height=1,\
            font=("",12),command=self.setInterval)
        self.btnInterval.place(x=250,y=187)

        self.lbRunTime=Label(self.win,text=MyGui.G_MONITOR_TITLE,font=("",12))
        self.lbRunTime.place(x=10,y=220)
        self.textStartTime=Text(self.win,width=6,height=1,font=("",12))
        self.textStartTime.place(x=120,y=220)
        self.textStartTime.delete(0.0,END)
        self.textStartTime.insert(INSERT,MyGui.gStartTime)
        self.lbRunTime2=Label(self.win,text='-',font=("",12))
        self.lbRunTime2.place(x=173,y=220)
        self.textEndTime=Text(self.win,width=6,height=1,font=("",12))
        self.textEndTime.place(x=190,y=220)
        self.textEndTime.delete(0.0,END)
        self.textEndTime.insert(INSERT,MyGui.gEndTime)
        self.btnRunTime=Button(self.win,text=MyGui.G_SAVE_BTN,width=5,height=1,\
            font=("",12),command=self.setRunTime)
        self.btnRunTime.place(x=250,y=217)

        self.lbStatus=Label(self.win,text=MyGui.G_STATUS_TITLE,font=("",12),foreground='blue')
        self.lbStatus.place(x=10,y=250)

        self.btnStart=Button(self.win,image=self.picStart,\
            text='start',command=self.startAi)
        self.btnStart.place(x=317,y=120)

        self.status=Status(self.win)
        self.status.start()
        self.debug=Debug(self.win)
        self.debug.start()
        self.wait=Wait(self.win)
        self.wait.start()
        self.watch=Watch(self.win)
        self.watch.start()

    def startAi(self):
        if self.btnStart['text']=='start':
            MyGui.bResetScene=True
            MyGui.bRunning=True
            MyGui.gRunTime=time.time()
            self.win.iconify()
            self.btnStart['text']='stop'
            self.btnStart['image']=self.picStop
            self.btnStart.focus()
            self.cmbGameMode.config(state=DISABLED)
            self.cmbZone.config(state=DISABLED)
            self.cmbFight.config(state=DISABLED)
            self.cmbSkill.config(state=DISABLED)
            self.cmbCard.config(state=DISABLED)
            self.check.config(state=DISABLED)
            self.btnBattle.config(state=DISABLED)
            self.btnTip.config(state=DISABLED)
            self.btnGameMode.config(state=DISABLED)
            self.btnZone.config(state=DISABLED)
            self.btnSkill.config(state=DISABLED)
            self.btnCard.config(state=DISABLED)
            self.btnInterval.config(state=DISABLED)
            self.btnRunTime.config(state=DISABLED)
            self.textZone.configure(state='disabled',foreground='grey')
            self.textInterval.configure(state='disabled',foreground='grey')
            self.textStartTime.configure(state='disabled',foreground='grey')
            self.textEndTime.configure(state='disabled',foreground='grey')
            self.lbBattle.configure(foreground='grey')
            self.lbGameMode.configure(foreground='grey')
            self.lbZone.configure(foreground='grey')
            self.lbSkill.configure(foreground='grey')
            self.lbCard.configure(foreground='grey')
            self.lbInterval.configure(foreground='grey')
            self.lbInterval2.configure(foreground='grey')
            self.lbRunTime.configure(foreground='grey')
            self.lbRunTime2.configure(foreground='grey')
        else:
            MyGui.bRunning=False
            MyGui.bAutoAi=False
            self.btnStart['text']='start'
            self.btnStart['image']=self.picStart
            self.cmbGameMode.config(state=NORMAL)
            self.cmbZone.config(state=NORMAL)
            self.cmbFight.config(state=NORMAL)
            self.cmbSkill.config(state=NORMAL)
            self.cmbCard.config(state=NORMAL)
            self.check.config(state=NORMAL)
            self.btnBattle.config(state=NORMAL)
            self.btnTip.config(state=NORMAL)
            self.btnGameMode.config(state=NORMAL)
            self.btnZone.config(state=NORMAL)
            self.btnSkill.config(state=NORMAL)
            self.btnCard.config(state=NORMAL)
            self.btnInterval.config(state=NORMAL)
            self.btnRunTime.config(state=NORMAL)
            self.textZone.configure(state='normal',foreground='black')
            self.textInterval.configure(state='normal',foreground='black')
            self.textStartTime.configure(state='normal',foreground='black')
            self.textEndTime.configure(state='normal',foreground='black')
            self.lbBattle.configure(foreground='black')
            self.lbGameMode.configure(foreground='black')
            self.lbZone.configure(foreground='black')
            self.lbSkill.configure(foreground='black')
            self.lbCard.configure(foreground='black')
            self.lbInterval.configure(foreground='black')
            self.lbInterval2.configure(foreground='black')
            self.lbRunTime.configure(foreground='black')
            self.lbRunTime2.configure(foreground='black')

    def tipInfo(self):
        tkinter.messagebox.showinfo(title=\
            MyGui.G_TIP_BTN,message=MyGui.G_TIP_INFO)

    def setBattle(self):
        file=filedialog.askopenfilename().replace('\n','')
        MyGui.gBattlePath=file
        self.textBattle.config(state=NORMAL)
        self.textBattle.delete(0.0,END)
        self.textBattle.insert(INSERT,file)
        self.textBattle.config(state=DISABLED)
        config=configparser.ConfigParser()
        config.read("config/config.ini",encoding="utf8")
        config.set("config","battlepath",file)
        o=open("config/config.ini","w",encoding="utf8")
        config.write(o)
        o.close()

    def setGameMode(self):
        i=0
        all=MyGui.G_LIST_MODE
        name1=self.cmbGameMode.get().replace('\n','')
        for name in all:
            if name1!=name:i+=1
            else:
                if i==0:MyGui.gGameMode='1'
                break
        config=configparser.ConfigParser()
        config.read("config/config.ini",encoding="utf8")
        config.set("config","gamemode",MyGui.gGameMode.replace('\n',''))
        o=open("config/config.ini","w",encoding="utf8")
        config.write(o)
        o.close()

    def setZone(self):
        config=configparser.ConfigParser()
        config.read("config/config.ini",encoding="utf8")

        #副本难度
        i=0
        all=MyGui.G_LIST_ZONE
        name1=self.cmbZone.get().replace('\n','')
        for name in all:
            if name1!=name:i+=1
            else:
                if i==0:MyGui.gDifficulty='1'
                elif i==1:MyGui.gDifficulty='2'
                break
        config.set("config","difficulty",MyGui.gDifficulty.replace('\n',''))

        #副本地图
        MyGui.gLevel=self.textZone.get(0.0,END).replace('\n','')
        config.set("config","level",self.textZone.get(0.0,END).replace('\n',''))

        #小关卡次数
        i=0
        all=MyGui.G_LIST_FIGHT
        name1=self.cmbFight.get().replace('\n','')
        for name in all:
            if name1!=name:i+=1
            else:
                if i==0:MyGui.gAbandon=99
                elif i==1:MyGui.gAbandon=88
                elif i==2:MyGui.gAbandon=999
                else:MyGui.gAbandon=i-2
                break
        config.set("config","abandon",str(MyGui.gAbandon).replace('\n',''))

        #点击任务
        MyGui.gViewTask=int(self.checkVar.get().replace('\n',''))
        config.set("config","task",self.checkVar.get().replace('\n',''))

        #保存
        o=open("config/config.ini","w",encoding="utf8")
        config.write(o)
        o.close()

    def setSkill(self):
        i=0
        all=MyGui.G_LIST_SKILL
        name1=self.cmbSkill.get().replace('\n','')
        for name in all:
            if name1!=name:i+=1
            else:
                if i==0:MyGui.gSkill='1'
                elif i==1:MyGui.gSkill='2'
                elif i==2:MyGui.gSkill='3'
                elif i==3:MyGui.gSkill='4'
                elif i==4:MyGui.gSkill='5'
                elif i==5:MyGui.gSkill='6'
                elif i==6:MyGui.gSkill='7'
                elif i==7:MyGui.gSkill='8'
                break
        config=configparser.ConfigParser()
        config.read("config/config.ini",encoding="utf8")
        config.set("config","skill",MyGui.gSkill.replace('\n',''))
        o=open("config/config.ini","w",encoding="utf8")
        config.write(o)
        o.close()

    def setCard(self):
        i=0
        all=MyGui.G_LIST_CARD
        name1=self.cmbCard.get().replace('\n','')
        for name in all:
            if name1!=name:i+=1
            else:
                if i==0:MyGui.gCard='1-1'
                elif i==1:MyGui.gCard='1-2'
                elif i==2:MyGui.gCard='1-3'
                elif i==3:MyGui.gCard='2-1'
                elif i==4:MyGui.gCard='2-2'
                elif i==5:MyGui.gCard='2-3'
                elif i==6:MyGui.gCard='3-1'
                elif i==7:MyGui.gCard='3-2'
                elif i==8:MyGui.gCard='3-3'
                break
        config=configparser.ConfigParser()
        config.read("config/config.ini",encoding="utf8")
        config.set("config","card",MyGui.gCard.replace('\n',''))
        o=open("config/config.ini","w",encoding="utf8")
        config.write(o)
        o.close()

    def setInterval(self):
        MyGui.gInterval=int(self.textInterval.get(0.0,END).replace('\n',''))
        config=configparser.ConfigParser()
        config.read("config/config.ini",encoding="utf8")
        config.set("config","interval",self.textInterval.get(0.0,END).replace('\n',''))
        o=open("config/config.ini","w",encoding="utf8")
        config.write(o)
        o.close()

    def setRunTime(self):
        MyGui.gStartTime=self.textStartTime.get(0.0,END).replace('\n','')
        MyGui.gEndTime=self.textEndTime.get(0.0,END).replace('\n','')
        config=configparser.ConfigParser()
        config.read("config/config.ini",encoding="utf8")
        config.set("config","starttime",MyGui.gStartTime.replace('\n',''))
        config.set("config","endtime",MyGui.gEndTime.replace('\n',''))
        o=open("config/config.ini","w",encoding="utf8")
        config.write(o)
        o.close()
